<script type="text/javascript">
	//表格查询  
	function reloadProcessInstances() {
		var params = processInstances_list.datagrid('options').queryParams; //先取得 datagrid 的查询参数  
		printLog(params);
		processInstances_list.datagrid('reload'); //设置好查询参数 reload 一下就可以了  
		processInstances_list.datagrid('unselectAll');
		processInstances_list.datagrid('uncheckAll');
	}
	
	function clearProcessInstancesSearch() {
		setGridSearchParams('processInstances_list','processInstancesSearchForm',true,reloadProcessInstances);
	}
	
	//根据条件查询
	function processInstancesSearch() {
		setGridSearchParams('processInstances_list','processInstancesSearchForm',false,reloadProcessInstances);
	}
	var diag = null;
	function addProcessInstances(id) {
	 	url = "processInstances.do?processInstancesOpen";
	 	if(id != "")
	 	{
	 		url = "processInstances.do?processInstancesOpen&id=" + id;
	 	}
	 	diag = createFromWindowOptions({
			title:"新增流程模型",
			maximizable:true,
			width:document.body.clientWidth,
			height:document.body.clientHeight,
			href:url,
			callback:function(d) {
			},
			enableCloseButton : false,
			closable : false,
			enableSaveButton:false
		});
	}
	
	function deleteProcessInstances() {
		var rows = processInstances_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('processInstances.do?processInstancesRemove',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadProcessInstances();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	//操作按钮触发
	function operationsLookProcessInstances(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = processInstances_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) 
		{
			$.messager.confirm('询问','你确认要发布吗?',function(r){
	            if (r){
	                $.post('processInstances.do?processInstancesDeploy',{id:id},function(result){
	                    if (result.success){
	                    	reloadProcessInstances();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
		} 
		else 
		{
			showMsg('请选择查看记录.');
		}
	}
	
	function operationsDeleteProcessInstances(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = processInstances_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			$.messager.confirm('询问', '你确认要删除吗?', function(r) {
				if (r) {
					$.post('processInstances.do?processInstancesRemove', {
						ids : id
					}, function(result) {
						if (result.success) {
							reloadProcessInstances(); 
						}
						showMsg(result.msg);
					}, 'json');
				}
			});
		} else {
			showMsg("请选择操作记录.");
		}
	}

	function operationsEditProcessInstances(id) {
		addProcessInstances(id);
	}
	
	/**
	 * 激活
	 */
	function activeProcessInstances() {
		 var rows = processInstances_list.datagrid('getChecked');
		    if (rows&&rows.length>0){
		        $.messager.confirm('询问','你确认要激活吗?',function(r){
		        	if (r){
		            	var ids = "";
		            	for(var i=0; i<rows.length; i++)
		            	{
		            		if(!rows[i].suspended)
		            		{
		            			showMsg("请选择已挂起的记录.");
		            			return;
		            		}
		            		ids += rows[i].id+",";
		            	}
		            	
		                $.post('processdef.do?activeProcessInstances',{ids:ids},function(result){
		                    if (result.success){
		                    	reloadProcessInstances();    
		                    }
		                    showMsg(result.msg);
		                },'json');
		            }
		        });
		    }else {
		    	showMsg("请选择操作记录.");
		    }
	}
	/**
	 * 挂起
	 */
	function suspendedProcessInstances() {
		var rows = processInstances_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要挂起吗?',function(r){
	        	if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++)
	            	{
            			if(rows[i].suspended)
	            		{
	            			showMsg("请选择已激活的记录.");
	            			return;
	            		}
	            		ids += rows[i].id+",";
	            	}
	                $.post('processdef.do?suspendProcessInstances',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadProcessInstances();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	function showProcessInstances()
	{
		var rows = processInstances_list.datagrid('getChecked');
	    if (rows&&rows.length>0)
	    {
	    	if(rows.length > 1)
	    	{
	    		showMsg("请选择操作1条记录.");
	    	}
	    	else
	    	{	
	    		id = rows[0].id;
	    		
	    		createFromWindowOptions({
					title:"查看流程图",
					maximizable:true,
					width:document.body.clientWidth,
					height:document.body.clientHeight,
					href:'processdef.do?graphProcessDefPage&ids='+id,
					callback:function(d) {
					},
					enableSaveButton:false
				});
	    	}
	    }
	    else 
	    {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	function showXMLProcessInstances()
	{
		var rows = processInstances_list.datagrid('getChecked');
	    if (rows&&rows.length>0)
	    {
	    	if(rows.length > 1)
	    	{
	    		showMsg("请选择操作1条记录.");
	    	}
	    	else
	    	{	
	    		id = rows[0].id;
				props=window.open('processdef.do?consoleViewXml&processInstancesId=' + id, 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=1366, height=768');
	    		
// 	    		createFromWindowOptions({
// 					title:"查看流程图",
// 					maximizable:true,
// 					width:document.body.clientWidth,
// 					height:document.body.clientHeight,
// 					href:'processdef.do?processXmlPage&ids='+id,
// 					callback:function(d) {
// 						alert(123);
// 					},
// 					enableSaveButton:false
// 				});
	    	}
	    }
	    else 
	    {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	/**
	 * 编辑用户信息
	 */
	function editProcessInstances() {
		var rows = processInstances_list.datagrid('getChecked');
	    if (rows&&rows.length>0)
	    {
	    	if(rows.length > 1)
	    	{
	    		showMsg("请选择操作1条记录.");
	    	}
	    	else
	    	{	
	    		id = rows[0].id;
	    		createFromWindow("更新流程定义", 'processdef.do?beforeUpdateProcess&processInstancesId='+id, "processdef.do?updateProcess",
				function(data) {
					reloadProcessInstances();
				});
	    	}
	    }
	    else 
	    {
	    	showMsg("请选择操作记录.");
	    }
	}
	
</script>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
		<@eu.datagrid id="processInstances_list" toolbar="#processInstancesList_search"
		idField="id" url="processdef.do?listProcessInstances"
		rownumbers="true" onDblClickRow="onDblClickProcessInstancesRow(rowIndex,
		rowData)" item="com.xdtech.oa.bpm.vo.ProcessInstancesItem"/>

		<div id="processInstancesList_search">
			<div style="margin-bottom:5px;padding-left:5px;margin-top: 5px;">
				<form id="processInstancesSearchForm">
					<!-- 防止form表单里只有一个text元素时候，按enter键自动提交问题 -->
					<input style="display:none" />
					<table>
						<tr>
						<td class="tbLabel">名称：</td>
							<td><input class="easyui-validatebox textbox" name="name" style="width: 150px" />
						</td>
						<td rowspan="2">
							<@eu.linkbutton showName="查询" iconCls="icon-search" onclick="processInstancesSearch()"/>
 					 		<@eu.linkbutton showName="清空" iconCls="icon-clear" onclick="clearProcessInstancesSearch()"/>
					 	</td>
						</tr>
					</table>
				</form>

			</div>
			<div id="processInstances_toolbar" style="height: auto">
				<@eu.linkbutton
				showName="激活" shiro="bmp:processInstances:active" iconCls="icon-ok"
				onclick="activeProcessInstances()"/>
				
				<@eu.linkbutton
				showName="挂起" shiro="bmp:processInstances:suspended" iconCls="icon-no"
				onclick="suspendedProcessInstances()"/>
				
				<@eu.linkbutton showName="流程图" shiro="bmp:processInstances:showpro"
				iconCls="icon-add" onclick="showProcessInstances()"/> 
				
				<@eu.linkbutton
				showName="查看XML" shiro="bmp:processInstances:showxml" iconCls="icon-remove"
				onclick="showXMLProcessInstances()"/>  
				
				<@eu.linkbutton
				showName="diagram-viewer" shiro="bmp:processInstances:diagramviewer" iconCls="icon-remove"
				onclick="showMsg('尽请期待.');"/>  
				
				<@eu.linkbutton
				showName="编辑" shiro="bmp:processInstances:edit" iconCls="icon-edit"
				onclick="editProcessInstances()"/>  
				
				
				<@eu.linkbutton showName="刷新"
				shiro="bmp:processInstances:refresh" iconCls="icon-reload"
				onclick="reloadProcessInstances()"/></div>
		</div>
	</div>
</div>